﻿using System;
using my_proxy.RequestHandlers;
using my_proxy.Utils;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Collections.Generic;

namespace my_proxy
{
    class Program
    {
        /// <summary>
        /// Proxy server
        /// </summary>
        static void Main(string[] args)
        {
            FileReader fileReader = new FileReader();

            // --------- Configuration Variables ---------
            Configuration conf = Configuration.Read(fileReader);

            if (conf == null)
            {
                return;
            }

       
            Console.WriteLine("###############################");
            Console.WriteLine("Proxy Server " + conf.ProxyVersion + " has started.");
            Console.WriteLine("###############################");

           // ----------------output black list after Decryption------
          ;



           // ------------- Output black list --------------
            Console.WriteLine("\nBlack list:");
            fileReader.CreateEncryptedBlackListFile("list.txt", "blacklist.txt");
        //    fileReader.ReadList(conf.BlackFile).ForEach(Console.WriteLine);
            List<string> ans = fileReader.getDecryptedList("blacklist.txt");
        //    Console.WriteLine(fileReader.decryptData("AzcYUPD6s2ubeqQK+0OO6BxcsIdFW+7b"));
 

            fileReader.addEncryptedUser("127.0.0.1", "whitelist.txt");

            fileReader.addEncryptedUser("120.0.0.1", "whitelist.txt");

            fileReader.addEncryptedUser("127.30.0.1", "whitelist.txt");
            Console.WriteLine("done");
            // ------- Accept/Handle incoming requests ------- 
            new ProxyListener(conf, fileReader).HandleReq();

        }
    }
}